﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YinfangWeb.Model;

namespace YinfangWeb.DAL
{
    public partial class ProductFileDAO
    {
        #region 获取商品展示图片列表
        /// <summary>
		/// 获取全部记录列表
		/// </summary>
		/// <returns>实体列表</returns>
        public List<ProductFile> GetListBySpID(int spId,int fileType,int viewLogo)
        {
            var sql = "SELECT * FROM ProductFile WHERE FileType=@fileType AND ViewLogo=@viewLogo AND ProductDataID=@spId ORDER BY ViewOrder";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                var q = conn.Query<ProductFile>(sql,new {fileType,viewLogo, spId});
                return q.ToList();
            }
        }
        #endregion
        #region 删除商品的指定附件
        public int Delete(int spId,string fileName)
        {
            var sql = "DELETE ProductFile WHERE ProductDataID = @spId AND FileName=@fileName";
            var result = 0;
            using (var conn = ConnectionFactory.CreateConnection())
            {
                conn.Open();
                result = conn.Execute(sql, new { spId, fileName });
                conn.Close();
                return result;
            }
        }
        #endregion
    }
}
